package aar.test.tessocr.adapter;

import android.content.Context;
import android.text.SpannableString;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import aar.test.tessocr.adapter.interfaces.OnItemClickListener;
import aar.test.tessocr.model.CompanySearchModel;
import aar.test.tessocr.model.MoneyListModel;
import aar.test.tessocr.utils.KeywordUtil;
import clx.tessocr.ocreng.R;

/**
 * Created by 149-201605 on 2016/8/1.
 */

/*
* 主界面显示 dialog的资源适配器
* */
public class MoneyListAdapter extends BaseAdapter {

    private List<MoneyListModel> mList;

    private Context mContext;

    private OnItemClickListener listener;

    public MoneyListAdapter(Context mContext, List<MoneyListModel> mList) {
        this.mList = mList;
        this.mContext = mContext;


    }



    @Override
    public int getCount() {
        int count = 0;
        if (null != mList && !mList.isEmpty()) {
            count = mList.size();
        }
        return count;
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder showDialogHolder = null;
        if (null == convertView) {
            showDialogHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.money_list_item, null);
            showDialogHolder.title = (TextView) convertView.findViewById(R.id.title);
            showDialogHolder.title_time = (TextView) convertView.findViewById(R.id.title_time);
            showDialogHolder.title_bal = (TextView) convertView.findViewById(R.id.title_bal);
            convertView.setTag(showDialogHolder);

            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (listener != null) {
                        listener.onItemClick(position);
                    }
                }
            });
        } else {
            showDialogHolder = (ViewHolder) convertView.getTag();
        }


        if(TextUtils.equals(mList.get(position).getType(),"1")){

            showDialogHolder.title.setText("充值");

        }else if(TextUtils.equals(mList.get(position).getType(),"2")){

            showDialogHolder.title.setText("派件");

        }


        if(TextUtils.equals(mList.get(position).getStatus(),"1")){
            //+

            showDialogHolder.title_bal.setText("+"+Float.parseFloat(mList.get(position).getMoney())/100.0+"元");

        }else if(TextUtils.equals(mList.get(position).getStatus(),"2")){
            //-

            showDialogHolder.title_bal.setText("-"+Float.parseFloat(mList.get(position).getMoney())/100.0+"元");

        }


        showDialogHolder.title_time.setText(mList.get(position).getCreated_at());



        return convertView;
    }


    class ViewHolder {
        TextView title;
        TextView title_time;
        TextView title_bal;
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }
}


